package cn.moningxi.service.impl;

import cn.moningxi.bean.CPointLog;
import cn.moningxi.bean.CustomerInfomation;
import cn.moningxi.mapper.CPointLogMapper;
import cn.moningxi.service.CPointLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class CPointLogServiceImpl implements CPointLogService {
    @Autowired
    CPointLogMapper cPointLogMapper;

    @Override
    public List<CPointLog> queryPointList(CustomerInfomation onlineUser) {
        return cPointLogMapper.queryPointList(onlineUser);
    }


    @Override
    public Integer addPoint(CustomerInfomation onlineUser, Integer userPoint) {
        System.out.println(onlineUser.getCustomerId());
        CPointLog cPointLog = new CPointLog();
        cPointLog.setSource("1");
        cPointLog.setCustomerId(onlineUser.getCustomerId());
        cPointLog.setChargePoint(5);
        cPointLog.setCreateTime(LocalDateTime.now());

        if (cPointLogMapper.queryPointByDate(cPointLog) == 0) {
            cPointLogMapper.addPoint(cPointLog);
            return 0;
        } else {
            return 1;
        }
    }

    @Override
    public Integer isPoint(CustomerInfomation onlineUser, Integer userPoint) {
        CPointLog cPointLog = new CPointLog();
        cPointLog.setSource("1");
        cPointLog.setCustomerId(onlineUser.getCustomerId());
        cPointLog.setChargePoint(5);
        cPointLog.setCreateTime(LocalDateTime.now());
        if (cPointLogMapper.queryPointByDate(cPointLog) == 0) {
            return 0;
        } else {
            return 1;
        }
    }
}
